package team.star.werespos.controller;

import com.google.common.collect.Lists;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import team.star.werespos.config.QiniuConfig;
import team.star.werespos.model.vo.ResultVO;
import team.star.werespos.util.Result;
import team.star.werespos.util.UploadUtil;

import java.util.List;

/**
 * UploadController class<br/>
 *
 * @author hdonghong
 * @since 2018/10/19
 */
@RestController
@RequestMapping("/upload")
@Slf4j
public class UploadController {

    private QiniuConfig qiniuConfig;

    @Autowired
    public UploadController(QiniuConfig qiniuConfig) {
        this.qiniuConfig = qiniuConfig;
    }


    @PostMapping("/image")
    public ResultVO<String> uploadImage(
            @RequestParam("imageFile") MultipartFile imageFile) {
        String s = UploadUtil.uploadImage(imageFile, QiniuConfig.getImageURI(""), qiniuConfig);
        log.info("上传图片成功");
        return Result.success(s);
    }
}
